<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test.octave</title>
<meta name="generator" content="KF5::SyntaxHighlighting (Octave)"/>
</head><body style="color:#1f1c1b"><pre>
<span style="color:#898887;"># This is test comment</span>
<span style="color:#898887;">% this is another comment</span>
a = <span style="color:#b08000;">3</span>; b = <span style="color:#b08000;">34</span>;

<span style="font-weight:bold;">function</span> retval = avg (v)
  retval = <span style="color:#b08000;">0</span>;
  <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">isvector</span> (v))
    retval = <span style="color:#644a9b;">sum</span> (v) / <span style="color:#644a9b;">length</span> (v);
  <span style="font-weight:bold;">else</span>
    <span style="color:#644a9b;">error</span> (<span style="color:#bf0303;">&quot;avg: expecting vector argument&quot;</span>);
  <span style="font-weight:bold;">endif</span>
<span style="font-weight:bold;">endfunction</span>

<span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">rem</span> (x, <span style="color:#b08000;">2</span>) == <span style="color:#b08000;">0</span>)
  <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;x is even\n&quot;</span>);
<span style="font-weight:bold;">else</span>
  <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;x is odd\n&quot;</span>);
<span style="font-weight:bold;">endif</span>

<span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">rem</span> (x, <span style="color:#b08000;">2</span>) == <span style="color:#b08000;">0</span>)
  <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;x is even\n&quot;</span>);
<span style="font-weight:bold;">elseif</span> (<span style="color:#644a9b;">rem</span> (x, <span style="color:#b08000;">3</span>) == <span style="color:#b08000;">0</span>)
  <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;x is odd and divisible by 3\n&quot;</span>);
<span style="font-weight:bold;">else</span>
  <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;x is odd\n&quot;</span>);
<span style="font-weight:bold;">end</span>

<span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">rem</span>(x,<span style="color:#b08000;">2</span>) == <span style="color:#b08000;">0</span>) x = <span style="color:#b08000;">5</span>; <span style="font-weight:bold;">elseif</span> (<span style="color:#644a9b;">rem</span> (x,<span style="color:#b08000;">3</span>) == <span style="color:#b08000;">0</span>) x = <span style="color:#b08000;">3</span>; <span style="font-weight:bold;">else</span> x = <span style="color:#b08000;">0</span>; <span style="font-weight:bold;">end</span>

<span style="color:#644a9b;font-weight:bold;">cd</span> ..

<span style="font-weight:bold;">while</span> (<span style="color:#644a9b;">i</span> &lt;= <span style="color:#b08000;">10</span>)
  fib (<span style="color:#644a9b;">i</span>) = fib (<span style="color:#644a9b;">i</span>-<span style="color:#b08000;">1</span>) + fib (<span style="color:#644a9b;">i</span>-<span style="color:#b08000;">2</span>);
  <span style="color:#644a9b;">i</span>++;
<span style="font-weight:bold;">endwhile</span>

<span style="font-weight:bold;">classdef</span> polynomial2
  <span style="font-weight:bold;">properties</span>
    <span style="color:#644a9b;">poly</span> = <span style="color:#b08000;">0</span>;
  <span style="font-weight:bold;">endproperties</span>

  <span style="font-weight:bold;">methods</span>
    <span style="font-weight:bold;">function</span> p = polynomial2 (a)
      <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">nargin</span> &gt; <span style="color:#b08000;">1</span>)
        <span style="color:#644a9b;">print_usage</span> ();
      <span style="font-weight:bold;">endif</span>

      <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">nargin</span> == <span style="color:#b08000;">1</span>)
        <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">isa</span> (a, <span style="color:#bf0303;">&quot;polynomial2&quot;</span>))
          p.poly = a.poly;
        <span style="font-weight:bold;">elseif</span> (<span style="color:#644a9b;">isreal</span> (a) &amp;&amp; <span style="color:#644a9b;">isvector</span> (a))
          p.poly = a(:).';  <span style="color:#898887;"># force row vector</span>
        <span style="font-weight:bold;">else</span>
          <span style="color:#644a9b;">error</span> (<span style="color:#bf0303;">&quot;polynomial2: A must be a real vector&quot;</span>);
        <span style="font-weight:bold;">endif</span>
      <span style="font-weight:bold;">endif</span>
    <span style="font-weight:bold;">endfunction</span>

    <span style="font-weight:bold;">function</span> <span style="color:#644a9b;">disp</span> (p)
      a = p.poly;
      first = <span style="color:#644a9b;">true</span>;
      <span style="font-weight:bold;">for</span> <span style="color:#644a9b;">i</span> = <span style="color:#b08000;">1</span> : <span style="color:#644a9b;">length</span> (a);
        <span style="font-weight:bold;">if</span> (a(<span style="color:#644a9b;">i</span>) != <span style="color:#b08000;">0</span>)
          <span style="font-weight:bold;">if</span> (first)
            first = <span style="color:#644a9b;">false</span>;
          <span style="font-weight:bold;">elseif</span> (a(<span style="color:#644a9b;">i</span>) &gt; <span style="color:#b08000;">0</span> || <span style="color:#644a9b;">isnan</span> (a(<span style="color:#644a9b;">i</span>)))
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; +&quot;</span>);
          <span style="font-weight:bold;">endif</span>
          <span style="font-weight:bold;">if</span> (a(<span style="color:#644a9b;">i</span>) &lt; <span style="color:#b08000;">0</span>)
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; -&quot;</span>);
          <span style="font-weight:bold;">endif</span>
          <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">i</span> == <span style="color:#b08000;">1</span>)
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; %.5g&quot;</span>, <span style="color:#644a9b;">abs</span> (a(<span style="color:#644a9b;">i</span>)));
          <span style="font-weight:bold;">elseif</span> (<span style="color:#644a9b;">abs</span> (a(<span style="color:#644a9b;">i</span>)) != <span style="color:#b08000;">1</span>)
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; %.5g *&quot;</span>, <span style="color:#644a9b;">abs</span> (a(<span style="color:#644a9b;">i</span>)));
          <span style="font-weight:bold;">endif</span>
          <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">i</span> &gt; <span style="color:#b08000;">1</span>)
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; X&quot;</span>);
          <span style="font-weight:bold;">endif</span>
          <span style="font-weight:bold;">if</span> (<span style="color:#644a9b;">i</span> &gt; <span style="color:#b08000;">2</span>)
            <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; ^ %d&quot;</span>, <span style="color:#644a9b;">i</span> - <span style="color:#b08000;">1</span>);
          <span style="font-weight:bold;">endif</span>
        <span style="font-weight:bold;">endif</span>
      <span style="font-weight:bold;">endfor</span>

      <span style="font-weight:bold;">if</span> (first)
        <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot; 0&quot;</span>);
      <span style="font-weight:bold;">endif</span>
      <span style="color:#644a9b;">printf</span> (<span style="color:#bf0303;">&quot;\n&quot;</span>);
    <span style="font-weight:bold;">endfunction</span>
  <span style="font-weight:bold;">endmethods</span>
<span style="font-weight:bold;">endclassdef</span>
</pre></body></html>
